package com.joolun.web.controller.promotion;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.system.domain.EduCourseHour;
import com.joolun.system.service.IEduCourseHourService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 课程课时Controller
 * 
 * @author joolun
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/promotion/hour")
public class EduCourseHourController extends BaseController
{
    @Autowired
    private IEduCourseHourService eduCourseHourService;

    /**
     * 查询课程课时列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EduCourseHour eduCourseHour)
    {
        //startPage();
        List<EduCourseHour> list = eduCourseHourService.selectEduCourseHourList(eduCourseHour);
        return getDataTable(list);
    }

    /**
     * 导出课程课时列表
     */
    @PreAuthorize("@ss.hasPermi('promotion:hour:export')")
    @Log(title = "课程课时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduCourseHour eduCourseHour)
    {
        List<EduCourseHour> list = eduCourseHourService.selectEduCourseHourList(eduCourseHour);
        ExcelUtil<EduCourseHour> util = new ExcelUtil<EduCourseHour>(EduCourseHour.class);
        util.exportExcel(response, list, "课程课时数据");
    }

    /**
     * 获取课程课时详细信息
     */
    @GetMapping(value = "/{hourId}")
    public AjaxResult getInfo(@PathVariable("hourId") Long hourId)
    {
        return success(eduCourseHourService.selectEduCourseHourByHourId(hourId));
    }

    /**
     * 新增课程课时
     */
    @PreAuthorize("@ss.hasPermi('promotion:hour:add')")
    @Log(title = "课程课时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduCourseHour eduCourseHour)
    {
        eduCourseHour.setCreateBy(getUsername());
        return toAjax(eduCourseHourService.insertEduCourseHour(eduCourseHour));
    }

    /**
     * 修改课程课时
     */
    @PreAuthorize("@ss.hasPermi('promotion:hour:edit')")
    @Log(title = "课程课时", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduCourseHour eduCourseHour)
    {
        eduCourseHour.setCreateBy(getUsername());
        return toAjax(eduCourseHourService.updateEduCourseHour(eduCourseHour));
    }

    /**
     * 删除课程课时
     */
    @PreAuthorize("@ss.hasPermi('promotion:hour:remove')")
    @Log(title = "课程课时", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hourIds}")
    public AjaxResult remove(@PathVariable Long[] hourIds)
    {
        return toAjax(eduCourseHourService.deleteEduCourseHourByHourIds(hourIds));
    }
}
